import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { ProjectsService } from './projects.service';
import { CreateProjectDto } from './dto/create-project.dto';
import { UpdateProjectDto } from './dto/update-project.dto';
import {ApiOperation, ApiTags} from "@nestjs/swagger";
import {AllowAnon} from "../../common/decorators/allow-anon.decorator";
import QueryProjectDto from "./dto/query-projects.dto";

@ApiTags('项目总览列表')
@Controller('projects')
export class ProjectsController {
  constructor(private readonly projectsService: ProjectsService) {}

  @Post('add')
  @ApiOperation({ summary: '新增项目信息' })
  create(@Body() createProjectDto: CreateProjectDto) {
    return this.projectsService.create(createProjectDto);
  }

  @Post('update')
  @ApiOperation({ summary: '更新项目信息' })
  update(@Body() updateProjectDto: UpdateProjectDto) {
    return this.projectsService.update(updateProjectDto);
  }

  @AllowAnon()
  @Get('getAll')
  @ApiOperation({ summary: '获取所有项目列表' })
  findAll(@Body() queryProjectsDto: QueryProjectDto) {
    return this.projectsService.findAll(queryProjectsDto);
  }

  @AllowAnon()
  @Get('getList')
  @ApiOperation({ summary: '获取最新的项目列表，最多5个' })
  findList(@Body() queryProjectsDto: QueryProjectDto) {
    return this.projectsService.findList(queryProjectsDto);
  }

  @Delete('delete/:id')
  @ApiOperation({ summary: '删除项目信息' })
  remove(@Param('id') id: string) {
    return this.projectsService.remove(+id);
  }
}
